package tech.aistar.service.impl.dynamic;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.dynamic.ImgsStorage;
import tech.aistar.entity.dynamic.Picture;
import tech.aistar.mapper.ImgsStorageMapper;
import tech.aistar.mapper.PictureMapper;
import tech.aistar.service.IPictureService;

import java.util.List;

/**
 * Created by David on 2019/9/28.
 */
@Service
public class PictureServiceImpl implements IPictureService {

    @Autowired
    private PictureMapper pictureMapper;
    @Autowired
    private ImgsStorageMapper imgsStorageMapper;
    @Override
    public List<Picture> findAll() {
        return pictureMapper.findAll();
    }


    @Override
    public void addPicture(Picture picture) {
        pictureMapper.addPicture(picture);
    }


    @Override
    public Picture getByPicId(Integer picId) {
        return pictureMapper.getByPicId(picId);
    }


    @Override
    public List<Picture> findByPicType(String picType) {
        List<Picture> pictureList=pictureMapper.findByPicType(picType);
        return pictureList;
    }


    /**
     * 功能：上传图片
     * @param file 文件
     * @param uploadPath 服务器上上传文件的路径
     * @param physicalUploadPath  服务器上上传文件的物理路径
     * @return 上传文件的 URL相对地址
     */



    /**
     *多条件组合+分页查询
     * @param pageNum  当前页
     * @param pageSize  每页显示条数
     * @return
     */
    @Override
    public PageInfo<Picture> findAll2(Integer picId, String picType, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Picture> pictureList=pictureMapper.findByPicType(picType);
        PageInfo<Picture> pageInfo=new PageInfo<>(pictureList);
        return pageInfo;
    }

    /**
     * 根据图片id重图片库中查询
     * @param imgId
     * @return
     */
//    @Override
//    public List<ImgsStorage> findByImgId(Integer imgId) {
//
//        List<ImgsStorage> list=imgsStorageMapper.findByImgId(imgId);
//        return list;
//    }

    @Override
    public List<ImgsStorage> findImg() {
        List<ImgsStorage> list=imgsStorageMapper.findImg();
        return list;
    }

    @Override
    public List<Picture> findByUserId(Integer Id) {
        List<Picture> p=pictureMapper.findByUserId(Id);
        return p;
    }

    @Override
    public void delById(Integer id) {
        pictureMapper.delById(id);
    }
}
